using System;
using System.Collections.Generic;
using Newtonsoft.Json;

// WPF 相关（使用别名）
using WPF = System.Windows;
using WPFMedia = System.Windows.Media;

namespace PC.Models
{
    public class ChatUser
    {
        public string UserId { get; set; } = string.Empty;
        public string Username { get; set; } = string.Empty;
        public string Status { get; set; } = "online";
    }

    public class ChatMessage
    {
        public string Content { get; set; } = string.Empty;
        public string SenderName { get; set; } = string.Empty;
        private DateTime _timestamp;
        public string Timestamp 
        { 
            get => _timestamp.ToString("yyyy-MM-dd HH:mm:ss");
            set => _timestamp = DateTime.Parse(value);
        }
        public string DisplayTime
        {
            get
            {
                if (_timestamp.Date == DateTime.Today)
                {
                    return _timestamp.ToString("HH:mm:ss");
                }
                return _timestamp.ToString("yyyy-MM-dd HH:mm:ss");
            }
        }
        public bool IsPrivate { get; set; }
        public bool IsSystemMessage => SenderName == "System";
        public WPF.HorizontalAlignment Alignment { get; set; }
        public WPFMedia.Brush Background { get; set; } = new WPFMedia.SolidColorBrush(WPFMedia.Colors.Transparent);
        public ChatFileInfo? FileInfo { get; set; }
    }

    public class MessageEventData
    {
        public string MessageId { get; set; } = string.Empty;
        public string UserId { get; set; } = string.Empty;
        public string Username { get; set; } = string.Empty;
        public string Message { get; set; } = string.Empty;
        public DateTime Timestamp { get; set; }
        public bool IsPrivate { get; set; }
        public MessageRecipient? To { get; set; }
        public List<ReadStatus> ReadBy { get; set; } = new();
        public ChatFileInfo? FileInfo { get; set; }
    }

    public class MessageRecipient
    {
        public string UserId { get; set; } = string.Empty;
        public string Username { get; set; } = string.Empty;
    }

    public class PrivateMessageEventData
    {
        public string MessageId { get; set; } = string.Empty;
        public MessageRecipient From { get; set; } = new();
        public MessageRecipient To { get; set; } = new();
        public string Message { get; set; } = string.Empty;
        public DateTime Timestamp { get; set; }
        public List<ReadStatus> ReadBy { get; set; } = new();
        public ChatFileInfo? FileInfo { get; set; }
    }

    public class JoinedEventData
    {
        public string UserId { get; set; } = string.Empty;
        public string Username { get; set; } = string.Empty;
        public List<OnlineUserData> OnlineUsers { get; set; } = new();
    }

    public class OnlineUserData
    {
        public string UserId { get; set; } = string.Empty;
        public string Username { get; set; } = string.Empty;
        public string Status { get; set; } = string.Empty;
    }

    public class ReadStatus
    {
        public string UserId { get; set; } = string.Empty;
        public string Username { get; set; } = string.Empty;
        public DateTime ReadAt { get; set; }
    }

    public class MessageReadStatus
    {
        public string MessageId { get; set; } = string.Empty;
        public List<ReadStatus> ReadBy { get; set; } = new();
    }

    public class MessageDeletedData
    {
        public string MessageId { get; set; } = string.Empty;
        public string DeletedBy { get; set; } = string.Empty;
    }

    public class ChatFileInfo
    {
        [JsonProperty("fileId")]
        public string FileId { get; set; } = string.Empty;

        [JsonProperty("filename")]
        public string Filename { get; set; } = string.Empty;

        [JsonProperty("originalname")]
        public string OriginalName { get; set; } = string.Empty;

        [JsonProperty("url")]
        public string Url { get; set; } = string.Empty;

        [JsonProperty("mimetype")]
        public string MimeType { get; set; } = string.Empty;

        [JsonProperty("size")]
        public long Size { get; set; }
    }

    public class UserInfo
    {
        public string UserId { get; set; } = string.Empty;
        public string Username { get; set; } = string.Empty;
        public string Status { get; set; } = "online";
    }
} 